package com.ruicar.afs.cloud.common.mq.rabbit.message;

import com.alibaba.fastjson.annotation.JSONField;
import com.ruicar.afs.cloud.common.core.enums.AfsEnumDeserializer;
import com.ruicar.afs.cloud.common.core.enums.AfsEnumSerializer;
import com.ruicar.afs.cloud.common.mq.rabbit.constant.AfsRabbitMqConstants;
import lombok.Data;
import org.springframework.util.StringUtils;


/**
 * The type RabbitMessageWrapper
 * <p>Description: </p>
 *
 * @author Fzero
 * @version 1.0
 * @date Created on 2020.06.12 09:44:18
 * @since 1.0
 */
@Data
public class RabbitMessageWrapper {
    /**
     * Tag
     * <p>Description: </p>
     */
    String tag;
    /**
     * Id
     * <p>Description: </p>
     */
    String afsMessageId;
    /**
     * Content
     * <p>Description: </p>
     */
    String content;

    @JSONField(deserializeUsing = AfsEnumDeserializer.class, serializeUsing = AfsEnumSerializer.class)
    private MqTransCode transCode;

    boolean afsEntity;

    /**
     * Is afs message boolean
     *
     * @return the boolean
     */
    public boolean isAfsMessage() {
        return !StringUtils.isEmpty(tag) && !StringUtils.isEmpty(afsMessageId) && StringUtils.startsWithIgnoreCase(tag, AfsRabbitMqConstants.AFS_TAG);
    }
}
